class QueenAttackCalculator {

    private final BoardCoordinate boardCoordinate;
    private final BoardCoordinate anotherBoardCoordinate;

    QueenAttackCalculator(BoardCoordinate boardCoordinate, BoardCoordinate anotherBoardCoordinate) {
        if (boardCoordinate == null || anotherBoardCoordinate == null) {
            throw new IllegalArgumentException("You must supply valid board coordinates for both Queens.");
        }

        if (boardCoordinate.equals(anotherBoardCoordinate)) {
            throw new IllegalArgumentException("Queens may not occupy the same board coordinate.");
        }

        this.boardCoordinate = boardCoordinate;
        this.anotherBoardCoordinate = anotherBoardCoordinate;
    }

    boolean canQueensAttackOneAnother() {
        return this.canHorizontalAttackOneAnother() ||
                this.canVerticalAttackOneAnother() ||
                this.canSlantingAttackFromLeftToRight() ||
                this.canSlantingAttackFromRightToLeft();
    }

    private boolean canHorizontalAttackOneAnother() {
        return this.boardCoordinate.getY() == this.anotherBoardCoordinate.getY() &&
                this.boardCoordinate.getX() != this.anotherBoardCoordinate.getX();
    }

    private boolean canVerticalAttackOneAnother() {
        return this.boardCoordinate.getX() == this.anotherBoardCoordinate.getX() &&
                this.boardCoordinate.getY() != this.anotherBoardCoordinate.getY();
    }

    private boolean canSlantingAttackFromLeftToRight() {
        int oneX = this.boardCoordinate.getX();
        int oneY = this.boardCoordinate.getY();
        while (true) {
            if (oneX == this.anotherBoardCoordinate.getX() && oneY == this.anotherBoardCoordinate.getY()) {
                return true;
            }

            oneX--;
            oneY--;
            if (oneX < 0 || oneY < 0) {
                break;
            }
        }

        oneX = this.boardCoordinate.getX();
        oneY = this.boardCoordinate.getY();
        while (true) {
            if (oneX == this.anotherBoardCoordinate.getX() && oneY == this.anotherBoardCoordinate.getY()) {
                return true;
            }

            oneX++;
            oneY++;
            if (oneX > 7 || oneY > 7) {
                break;
            }
        }

        return false;
    }

    private boolean canSlantingAttackFromRightToLeft() {
        int oneX = this.boardCoordinate.getX();
        int oneY = this.boardCoordinate.getY();
        while (true) {
            if (oneX == this.anotherBoardCoordinate.getX() && oneY == this.anotherBoardCoordinate.getY()) {
                return true;
            }

            oneX++;
            oneY--;
            if (oneX > 7 || oneY < 0) {
                break;
            }
        }

        oneX = this.boardCoordinate.getX();
        oneY = this.boardCoordinate.getY();
        while (true) {
            if (oneX == this.anotherBoardCoordinate.getX() && oneY == this.anotherBoardCoordinate.getY()) {
                return true;
            }

            oneX--;
            oneY++;
            if (oneX < 0 || oneY > 7) {
                break;
            }
        }

        return false;
    }
}

class BoardCoordinate {

    private final int x;
    private final int y;

    BoardCoordinate(int x, int y) {
        if (x < 0) {
            throw new IllegalArgumentException("Coordinate must have positive row.");
        }

        if (y < 0) {
            throw new IllegalArgumentException("Coordinate must have positive column.");
        }

        if (x > 7 ) {
            throw new IllegalArgumentException("Coordinate must have row <= 7.");
        }

        if (y > 7 ) {
            throw new IllegalArgumentException("Coordinate must have column <= 7.");
        }

        this.x = x;
        this.y = y;
    }

    boolean equals(BoardCoordinate obj) {
        return this.x == obj.x && this.y == obj.y;
    }

    int getY() {
        return y;
    }

    int getX() {
        return x;
    }
}